<style>
  #_location_popup {
    -moz-border-radius: 6px;
    background: #eef2f7;
    -webkit-border-radius: 6px;
    border: 1px solid #536376;
    -webkit-box-shadow: rgba(0,0,0,.6) 0px 2px 12px;
    -moz-box-shadow:  rgba(0,0,0,.6) 0px 2px 12px;
    border-radius: 6px;
    padding: 14px;
    width: 370px;
    position: relative;
    height:170px;
    display: none;
  }
  #close_x {
    height: 41px;
    line-height: 1000px;
    position: absolute;
    right: -20px;
    top: -20px;
    width: 40px;
    background: url('<?php echo base_url() . APPPATH ?>themes/welcome/img/close.png') no-repeat;
  }
</style>
<script type="text/javascript">
  $('#change_location').click(function(e) {
    $('#_location_popup').lightbox_me({
      centered: true
    });
    e.preventDefault();
  });
  var base_url='<?php echo site_url(); ?>';
  var country_id = 0, state_id = 0;
  jQuery(document).ready(function(){
    $('#country_id').bind({
      change: function (){detect_country_search($(this).val());},
      blur: function (){detect_country_search($(this).val());}
    });

    $('#state_id').bind({
      change: function (){detect_state_search($(this).val());},
      blur: function (){detect_state_search($(this).val());}
    }); 	
    detect_country_search($('#country_id').val());        
  });
  function detect_country_search(id){
    if(country_id != id){
      country_id = id;
      $('#state_id').html('<option value=""><?php echo $this->lang->line('label.state.select') ?></option>');
      if(id){
        $.post('<?php echo site_url('admin/ajax/list_json_state') ?>', {id : id}, function(data){		  
          if(data && data.length > 0){
            $.each(data, function(key, value){
              $('#state_id').append('<option '+
                (value['id'] == '<?php echo userdata('state_id') ? userdata('state_id') : 0 ?>' ? 'selected="selected"' :'' )
                +' value="'+value['id']+'">'+ value['name'] +'</option>');
              if(value['id'] == '<?php echo userdata('state_id') ? userdata('state_id') : 0 ?>'){
                detect_state_search(value['id']);
              }
            })
          }
        }, 'json');
      }
    }
  }
  
  function detect_state_search(id){
    if(state_id != id){
      state_id = id;
      $('#city_id').html('<option value=""><?php echo $this->lang->line('label.city.select') ?></option>');
      if(id){
        $.post('<?php echo site_url('admin/ajax/list_json_city') ?>', {id : id}, function(data){
          if(data && data.length > 0){
            $.each(data, function(key, value){
              $('#city_id').append('<option '+
                (value['id'] == '<?php echo userdata('city_id') ? userdata('city_id') : 0 ?>' ? 'selected="selected"' :'' )
                +' value="'+value['id']+'">'+ value['name'] +'</option>');
            })
          }
        }, 'json');
      }
    }
  }
</script>
<div id="_location_popup">
  <div>
    <div class="font30" style="color:#E06604">Select your location</div>
    <div class="mg10" style="overflow: auto;height:450px"> 
      <div class="rp_box">
        <br />
        <div>
          <form action="<?php echo site_url('index/location') ?>" method="post" id="form_location">
            <input type="hidden" name="current_url" value="<?php echo current_url() ?>"/>
            <div id="currencies_block_top">
              <select name="country_id" id="country_id" style="color:#FFD700" >
                <option value="">Select country ...</option>
                <?php
                $ref_objs = $this->country_model->get_all();
                foreach ($ref_objs as $ref) {
                  ?>
                  <option value="<?php echo $ref["id"] ?>"
                          <?php echo !userdata('country_id') || userdata('country_id') != $ref["id"] ? "" : 'selected="selected"' ?>>
                            <?php echo $this->country_model->to_string($ref) ?>
                  </option>
                <?php } ?>
              </select>
              <select name="state_id" id="state_id" style="color:#FFD700">
                <option value="">Select state ...</option>
              </select>
              <select name="city_id" id="city_id" style="color:#FFD700">
                <option value="">Select city ...</option>
              </select>
            </div>
          </form>
        </div>
        <div class="mg10 mg_left80">
          <a href="#" onclick="jQuery('#form_location').submit();return false;" style="position: absolute;right:10px;bottom:10px">
            <img src="<?php echo base_url() . APPPATH ?>themes/user/img/next.png" /></a></div>
      </div>
    </div>    
  </div>  
  <a id="close_x" class="close sprited" href="#"></a>
</div>